Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / model / src / commonTest / kotlin / org / meshtastic / core / model / util / SnrExtensionsTest.kt

Displaying Raw • Download

core/model/src/commonTest/kotlin/org/meshtastic/core/model/util/SnrExtensionsTest.kt b4bedd92fcc8d65daff79200d71f6ebc3d8f0cfa (b4bedd92) Text, 3.20 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.model.util

Tff7b72import T7ee787org.meshtastic.proto.MeshPacket
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertEquals
Tff7b72import T7ee787kotlin.test.assertNotNull

T8b949e/**
* Guards the presence policy for `rx_snr`: absent means null and nothing else. Unlike [rxTimeOrNull], a zero must never
* be folded into "unknown" — 0 dB is a real measurement. See [snrOrNull].
*
* The proto-absent case is not asserted here because it is not yet constructible: `rx_snr` is still a non-null `float`
* upstream, so [snrOrNull] cannot return null for any packet this test could build. What these tests do lock down is
* the half that can regress today — that a zero is never folded — which is exactly what breaks if the [rxTimeOrNull]
* pattern is copied over. Null *handling* is covered where a null is representable: `MetricFormatterTest`
* (`snrAbsentIsUnknown`) and `LoraSignalIndicatorUiTest` (`snrRendersNothingWhenAbsent`,
* `loraSignalIndicatorShowsUnknownWhenSnrIsAbsent`).
*/
Tff7b72class T56d364SnrExtensionsTest Tb4b4b4{

Tff7b72private Tff7b72fun Td2a8ffloraPacketTb4b4b4(Te6edf3snrTb4b4b4: Tffa657FloatTb4b4b4) Tff7b72= Te6edf3MeshPacketTb4b4b4(
Te6edf3rx_time Tff7b72= T79c0ff1Te6edf3_700_000_000Tb4b4b4,
Te6edf3rx_snr Tff7b72= Te6edf3snrTb4b4b4,
Te6edf3hop_start Tff7b72= T79c0ff3Tb4b4b4,
Te6edf3hop_limit Tff7b72= T79c0ff3Tb4b4b4,
Te6edf3transport_mechanism Tff7b72= Te6edf3MeshPacketTb4b4b4.Te6edf3TransportMechanismTb4b4b4.Te6edf3TRANSPORT_LORATb4b4b4,
Tb4b4b4)

Tf0883e@Test
Tff7b72fun Td2a8ff`snrOrNull reports a negative reading`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// The common case: SNR below the noise floor but still demodulable on a long preset.
Te6edf3assertEqualsTb4b4b4(Tff7b72-T79c0ff1T79c0ff2.5fTb4b4b4, Te6edf3loraPacketTb4b4b4(Tff7b72-T79c0ff1T79c0ff2.5fTb4b4b4)Tb4b4b4.Te6edf3snrOrNullTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`snrOrNull reports a positive reading`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertEqualsTb4b4b4(T79c0ff6.5fTb4b4b4, Te6edf3loraPacketTb4b4b4(T79c0ff6.5fTb4b4b4)Tb4b4b4.Te6edf3snrOrNullTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`snrOrNull treats a true zero as a measurement rather than as absent`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// The whole point of the policy. A zero-folding `takeIf { it != 0f }` here would silently discard a signal
T8b949e// sitting exactly at the noise floor — comfortably demodulable on every preset — and would also throw away
T8b949e// the only zero that can reach us, since a zero from firmware predating the optional conversion is never put
T8b949e// on the wire and so already decodes to null.
Tff7b72val Te6edf3snr Tff7b72= Te6edf3loraPacketTb4b4b4(T79c0ff0fTb4b4b4)Tb4b4b4.Te6edf3snrOrNullTb4b4b4(Tb4b4b4)
Te6edf3assertNotNullTb4b4b4(Te6edf3snrTb4b4b4)
Te6edf3assertEqualsTb4b4b4(T79c0ff0fTb4b4b4, Te6edf3snrTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`snrOrNull does not conflate a zero reading with an unknown one`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Regression guard for the rx_time seam's pattern being copied over verbatim.
Te6edf3assertEqualsTb4b4b4(T79c0ff0fTb4b4b4, Te6edf3loraPacketTb4b4b4(T79c0ff0fTb4b4b4)Tb4b4b4.Te6edf3snrOrNullTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3assertEqualsTb4b4b4(Tff7b72nullTb4b4b4, Te6edf3MeshPacketTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3rxTimeOrNullTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.04s